Search Results: "damog"

2 February 2009

David Moreno: And now Apache2::EmbedMP3 for your songs collections!

After I spent time working on Apache2::EmbedFLV, I thought it was a good idea to do the same for audio files, specifically MP3 files. So now that you have your MP3 files on your web server and they are accessible to the world, you may want to show them with an embedded audio player. Well, Apache2::EmbedMP3 is exactly for you! EmbedMP3 uses the fabulous WP Audio Player, a small, elegant, GPL Flash audio player, similarly to how Apache2::EmbedFLV uses Flowplayer. The interesting thing about EmbedMP3 is that you can display more interesting data on the template such as song name, artist, album, year and also lyrics, which was an interesting feature I added. In this fashion, it s very easy to just drop a whole bunch of files into a directory and all be served with the custom interface. You have to instruct Apache2:
<Files ~ "\.mp3$">
       SetHandler modperl
       PerlSetVar wpaudioplayer /audio-player/player.swf
       PerlSetVar wpaudioplayer_js /audio-player/wpaudioplayer.js
       PerlResponseHandler Apache2::EmbedMP3
</Files>
And that s it. Take a look at the documentation to see how to point it to specific locations for WP Audio Player, template file, etc. You can see the hack in action at http://dev.axiombox.com/~david/mp3. If it struggles a bit by buffering, it s because that s directly from my home Internet connection, so give it a small break :-) And, as I suggested the Radiohead video with EmbedFLV, I suggest now this Black Eyed Peas song, Like That, it s very catchy and I love it ;-) Go get the code at the Git repo or at CPAN (once it s updated and published).

19 January 2009

David Moreno: More Git tips?

Make sure you add the just launched git ready blog to your feed reader. Made by qrush. Audience applauds!

17 January 2009

David Moreno: Introducing Apache2::EmbedFLV Exposing FLVs with Flowplayer and a customized interface

Situation You have a bunch of Flash videos, FLV files. Every once in a while you dump new files on your publicly accessible Apache directory. You would like to give your users the ability to play those FLVs within a webpage you provide, instead of just serving them the files for a direct download. Maybe you want this for all FLVs, not only an specific directory. Solution Apache2::EmbedFLV!
<Files ~ "\.flv$">
  SetHandler modperl
  PerlResponseHandler Apache2::EmbedFLV
</Files>
So now, all your FLV files will be served through Apache2::EmbedFLV on mod_perl with a neat interface you can define yourself, and using the very nice and GPL ed Flowplayer. Apache2::EmbedFLV uses a default template, but you can define your own with:
<Files ~ "\.flv$">
  SetHandler modperl
  PerlSetVar template /path/to/your/template.tt
  PerlResponseHandler Apache2::EmbedFLV
</Files>
Also, Apache2::EmbedFLV expects to find Flowplayer (flowplayer.swf and flowplayer.controls.swf) on http://your.server.com/flowplayer.swf, the root of your server. So you can do something like this to make it work:
Alias /flowplayer.swf /home/web/flowplayer/flowplayer.swf
Alias /flowplayer.controls.swf /home/web/flowplayer/flowplayer.controls.swf
Or, you just define the flowplayer variable:
<Files ~ "\.flv$">
  SetHandler modperl
  # relative to the document root
  PerlSetVar flowplayer /swf/flowplayer.swf
  # or absolute:
  PerlSetVar flowplayer http://my.other.server/was/hacked/flowplayer.swf
  PerlResponseHandler Apache2::EmbedFLV
</Files>
Action! You can see it in action at http://axiombox.com/apache2-embedflv/flv. This Radiohead video is particularly cool :-) Getting it UPDATE: Oops! Fixed link to Flowplayer s website! flowplayer.org. Thanks to those who noticed and let me knew.

8 January 2009

David Moreno: Re: On DebGem

Wouter, I find your thinking on DebGem a bit overreacted. I think you are taking the product and commercial efforts that a company make as the proposed solution we ve all been expecting for a similar problem, which is not. You are considering DebGem to be an outcome provided by the Ruby community, which is not, to this issue. Phusion is obviously not the Ruby community, but part of it. How I see it, it s great: I applaud that more companies take a look at nice technologies and try to provide their own products. Since I do most of my work with both technologies (and others), Debian and Ruby, I find DebGem worth giving it a try, and if it solves the installation problems of some gems on different systems for me, my employer and the systems I maintain, why not pay for it. However that s all you can expect it to do, solve your gem installation problems and that s it, they are not proposing to change how gems are done or how Ruby libraries are implemented as packages in Debian, they are just a bridge, a shortcut, nothing else, nothing more. And if that bridge works and is well built and maintained, hurrah!

6 January 2009

David Moreno: Returning an specific HTTP status/return code and content with mod_perl 2

Making a simple PerlResponseHandler that does something like this:
sub handler  
    my($r) = shift;
    $r->content_type("text/plain");
    $r->print("You suck.\n");
    return Apache2::Const::HTTP_BAD_REQUEST;
 
doesn t make what you d be expecting. This is because mod_perl assumes, since you are specifying content type and something to print, that this is a legit and valid (200-ish) request. This is what you get:

POST http://myserver/resource --> 200 OK
Connection: close
Date: Mon, 05 Jan 2009 23:02:57 GMT
Content-Type: text/plain; charset=UTF-8
Client-Date: Mon, 05 Jan 2009 23:03:00 GMT
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
[ some headers snipped ]
You suck.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK<</title>
</head><body>
<h1>OK</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
So, yes, I was expecting to return a 400 Bad Request return with just You suck on the response body. mod_perl disagrees, which, kind of sucks if you are trying to make a RESTful service with mod_perl HTTP handlers and filters. To avoid this behaviour, this is one way to go:
sub handler  
    my($r) = shift;
    $r->status(400); # or the one you are interested in
    $r->content_type("text/plain");
    $r->print("You suck.");
    return Apache2::Const::OK;
 
You can also take a look at status_line that overrides status. You can also avoid the content_type method call if you are sloth enough. Now, this is what you get:

GET https://myserver/resource --> 400 Bad Request
Connection: close
Date: Mon, 05 Jan 2009 23:27:08 GMT
Content-Type: text/plain; charset=UTF-8
Client-Date: Mon, 05 Jan 2009 23:27:10 GMT
Client-Peer: 209.234.249.38:443
Client-Response-Num: 1
[ some headers snipped :) ]
You suck.
And so, beer awaits.

3 January 2009

David Moreno: Ruby goodies: Modules and methods for my everyday Ruby

I make a lot of Web script processing, whether scraping, webservices, systems administration, etc. Because I sometimes happen to repeat small and useful chunks of code for different projects, I thought that, given making new modules and methods is usually hassleless in Ruby, I should make my own set of methods and goodies I constantly use. Example 1, I sometimes miss Perl s LWP::Simple simplicity where I just pass a URL to a subroutine and get the content on a variable, quick, one-liner. Example 2, extract all links on a given URL on an array that I can then iterate and maybe fetch given the first example. Getting all A links is very easy to do, say with regex or with Hpricot (which should the best way to parse HTML), but most of the time I (and people, I d bet) need absolute URLs which is fairly more complex (relative, absolute URLs, BASE href declarations, etc, the same case as in Feedbag). Well, for different cases like that one, I ve started my own set of Ruby goodies. If you don t find them useful, I understand, they are mostly for my needs, I just want to make it public, because maybe, some other people might indeed find them useful. Simple installation:
sudo gem install damog-goodies -s http://gems.github.com/
As time and needs pass, I will be adding stuff into it. For the time being, here s both above examples in action:

>> require "goodies"
requiring /var/lib/gems/1.8/gems/damog-goodies-0.1/lib/goodies/array.rb
requiring /var/lib/gems/1.8/gems/damog-goodies-0.1/lib/goodies/lwr.rb
requiring /var/lib/gems/1.8/gems/damog-goodies-0.1/lib/goodies/html.rb
=> true
>> pp HTML::Links.find "damog.net"
["mailto:david-YOUKNOWTHEDEAL-axiombox.com",
 "http://log.damog.net/",
 "http://historiasdenuevayork.com",
 "http://axiombox.com/",
 "http://flickr.com/photos/raquelydavid",
 "http://last.fm/user/damog",
 "http://maggit.com.mx",
 "http://twitter.com/damog",
 "http://www.facebook.com/profile.php?id=670490388",
 "http://www.chess.com?ref_id=1380378",
 "http://www.chess.com",
 "http://www.chess.com/members/view/damog?ref_id=1380378",
 "http://www.chess.com/echess/create_game.html?uid=1380378&ref_id=1380378",
 "http://www.chess.com/home/game_archive.html?member=damog&ref_id=1380378"]
=> nil
>> pp HTML::Links.find("http://google.com").first(10)
["http://images.google.com/imghp?hl=en&tab=wi",
 "http://maps.google.com/maps?hl=en&tab=wl",
 "http://news.google.com/nwshp?hl=en&tab=wn",
 "http://www.google.com/prdhp?hl=en&tab=wf",
 "http://mail.google.com/mail/?hl=en&tab=wm",
 "http://www.google.com/intl/en/options/",
 "http://video.google.com/?hl=en&tab=wv",
 "http://groups.google.com/grphp?hl=en&tab=wg",
 "http://books.google.com/bkshp?hl=en&tab=wp",
 "http://scholar.google.com/schhp?hl=en&tab=ws"]
=> nil
>> get "debian.org"
[snip]
>> get("planeta.debian.net")[0, 100]
=> "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>>
Repository is, as usual, kindly hosted at GitHub on damog/goodies.

30 December 2008

David Moreno: Introducing Feedbag: Feed auto-discovery Ruby library/tool

Last week, I spent some time building a good (that I liked) feed auto-discovery tool to use in Ruby for other project I m building, rFeed. I liked CPAN s Feed::Find, and at some point I made a wrapper class to run a Perl script using such module, however, I wasn t happy by mixing it all. So, Feedbag was born:
>> require "rubygems"
=> true
>> require "feedbag"
=> true
>> Feedbag.find "log.damog.net"
=> ["http://feeds.feedburner.com/TeoremaDelCerdoInfinito",
 "http://log.damog.net/comments/feed/"]
>> planet_feeds = Feedbag.find("planet.debian.org")
[ ... ]
>> planet_feeds.first(3)
=> ["http://planet.debian.org/rss10.xml",
 "http://planet.debian.org/rss20.xml",
 "http://planet.debian.org/atom.xml"]
>> planet_feeds.size
=> 104
>>
It makes smart use of relative and absolute bases, hrefs, links, content types, etc. It is also a single Ruby file, so you can grab it and use it on your application. Plus, it only requires Hpricot as dependency. It can find all feeds linked on a web page, but it will return the most important at the beginning of the resulting array, so you will have the important one on the first results (see example above with Planet Debian). Synopsis, README and a brief tutorial have been placed at axiombox.com/feedbag. You can also take a look at the git repo, hosted in GitHub.

29 December 2008

David Moreno: Good looking Irb

Irb is a pain to work with when you don t know it enough. Fortunately, it can be configured extensively enough to make your Ruby interactive sessions much smoother. Pocahontas asked me to post my Irb configuration:
# ~/.irbrc
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:SAVE_HISTORY] = 5000
IRB.conf[:HISTORY_FILE] = "# ENV['HOME'] /.irb_history"
IRB.conf[:PROMPT_MODE] = :SIMPLE
require 'irb/completion'
require 'irb/ext/save-history'
require 'pp'
# load rubygems and wirble
require 'rubygems' rescue nil
require 'wirble'
require 'utility_belt'
# load wirble
Wirble.init
Wirble.colorize
Which makes Irb to look much much better: irb But it is not only coloring the features you are getting, but also Readline support, command history saving, tab completion, libraries loaded by default, persistent history with Wirble, etc, etc. as you can see yourself on the very self-explanatory configuration file. Enjoy. Update: I have to thank my co-worker Galin for pointing me most of these neat features.

25 December 2008

Jose Carlos Garcia Sogo: git tips

Git is becoming my main utility for Debian packaging, as I am using it to keep my work on packages I maintain alone or in a team by using git.debian.org facilities. I am not still using tools like TopGit to keep patches, by I also intend to do so in a near future.
What does git give me over svn? Basically two things: branches and having the whole source code at hand. The first is obvious, I can easily create branches to experiment without having to change anything in the way the package is, so if a new upstream release occurs in the time it takes me to implement some change (and that usually happens) I can upload it straight, not affecting my undergoing changes.
Also I appreciate having the whole source code. This could have been also done using svn, but we preferred not to do so, and most packages only have debian dir in their svn repositories. This makes harder work with upstream sources, where they need to be patched. Git provides me the way to have always an upstream source code copy at hand, and the branch power can also be applied to it.
But I wanted to write about a couple of git tips that I found. Seems that they have already appeared on Planet Debian before, but I think that is not a bad idea to remember them (from damog s blog):

1. Changing into a directory that contains a repo and shows you on PS1 what branch you are standing on:

On .bashrc I have:

GITPS1='$(__git_ps1 ":%s ")'
export PS1="$ GREEN \w$ RS $ YELLOW $ GITPS1 $ RS \\$ "

But what I didn t want to lose was the code that was posted to paste.bin after in a comment someone pointed out that this trick was a bit annying if your home dir were also a git repo. This is one solution:

__maybe_git_ps1 ()
local BRANCH="$(__git_ps1 '%s')"
case "$BRANCH" in
master)
# silent
;;
'')
# not a git repo? -> silent
;;
*)
if [ -n "$1" ]; then
printf $1 $BRANCH
else
printf (%s) $BRANCH
fi
;;
esac

2. An alias I like to use on repos that are personal for quick tracking:

[alias]

log1 = log pretty=oneline abbrev-commit
Thanks damog for these tips!

23 December 2008

Ond&#345;ej &#268;ert&iacute;k: Experience with git after 4 months

I switched to git from mercurial about 4 months ago. As Matt Mackall (the main author of mercurial) has pointed out, my arguments were partially just excuses for the switch, because everything could be fixed in mercurial as well (eventually). On the other hand, I really wasn't expecting to switch when I invested time and energy to learn mercurial. Also because I thought that git doesn't have such a nice documentation, has a steep learning curve and the community is hostile, because it is developed by the kernel people who are famous for sometimes being not so nice on the mailinglists (as I now found out, none of these are true). I was getting annoyed by small things one by one, after finally I said to myself enough is enough, let's just switch.

So as to the steep learning curve --- it took me a day or two to being able to do what I want, so it seems to me it's really easy to learn once you know some distributed vcs. I found out the documentation is much better than in mercurial --- in git one just types "git help command" and a full man page fires up with lot's of information and examples. In mercurial, one just gets a couple lines (compared to git) of help in the terminal, without examples. Also the first (actually second) thing I noticed is that "git log" (and other commands like "git diff") doesn't scroll out my terminal, but uses "less" automatically -- that's just great. The first thing I noticed is that git is superfast for almost every operation, especially it's noticeable with "git diff". As to the community, I only had a chance to send a few emails to the git list, so I cannot really say, but so far it's very responsive and friendly.

However, those are just little things that can (and I am sure they will) be fixed in mercurial as well. What is a big thing are branches, especially remote branches. One just fetches a remote repository and then works with it like with any other local branch, e.g. one can switch to it, or just "git log some_remote_branch" to see what is in there. One can easily compare them etc. With mercurial, I was using "hg out" and "hg in" commands to see what changes I will pull or push, but those commands require internet connection, so it really sucks and it's slow. In mercurial, I was using different directories for different branches, but that's just extremely inconvenient and also slow (creating a new branch is just a matter of adding one file, not copying the whole repository --- for example with the sympy hg repository, I often had to wait several seconds to clone a repo, while with the git repository it's just instant) and big (in terms of megabytes).

The bible of Mercurial, the hgbook says:
In most instances, isolating branches in repositories is the right approach.

But I think it's the wrong approach. The only argument for doing this that I accept is that sometimes you are not sure which branch you are in in git --- well, I use this trick (actually, just read the documentation of __git_ps1 in /etc/bash_completion.d/git), so my bash line always says which branch I am in using the red color. I never do any mistakes with this.

Anyways, I could continue like this (e.g. check out "git svn", "git rebase -i" and many other things), but you can read why git is better for example here, no need to repeat here. I am very happy now and I can only recommend to learn git.

So let me also say some things that are worse in git --- one thing that could be improved are URLs of the gitweb (hgweb urls are neat, gitweb urls use "?id=..." stuff). Another thing is that the debian package git is not git! You need to install git-core to get git (but this seems to be getting fixed).

There is also an interesting discussion happening right now in the debian-python mailinglist about switching the DPMT repositories to git. I think almost all opinions (for and against) were already stated, but if you have some opinion that wasn't yet said, please do so.

13 December 2008

Martin F. Krafft: Aggregating Git tips

Instead of commenting on all the recent Git on Planet Debian, I d like to point you all to the Git Wiki, and specifically the page BlogPosts. Please link your Git-related blog posts from there. Also, there is Planet RCS for you to aggregate RCS/VCS-relatd posts. NP: Anekdoten: From Within

12 December 2008

David Moreno: Two Git tips

Following the Git tips being thrown on Planet Debian, here s a couple: 1. Changing into a directory that contains a repo and shows you on PS1 what branch you are standing on:
On .bashrc I have:
GITPS1='$(__git_ps1 ":%s ")'
export PS1="$ GREEN \w$ RS  $ YELLOW $ GITPS1 $ RS \\$ "
2. An alias I like to use on repos that are personal for quick tracking:
[alias]
  ...
  log1 = log --pretty=oneline --abbrev-commit
I hope you like them.

9 December 2008

David Moreno: High-Order Perl available for free

My friend Marco first told me on IM, then I read it on PerlBuzz. The nice High-Order Perl book by
Mark Jason Dominus is now available for free (as in free beer) at its website. This book caught my attention a long time ago on a Barnes & Noble once, but since I had just too many book on queue, I decided not to buy it. I then read that it’s actually a good book on “advanced” techniques on Perl, so my interest grew, but for random reasons I just didn’t get it. Now I have no excuses not to, and either do you :)

2 December 2008

David Moreno Garza: DirectoryIndex and the perl-script handler

Wouter Verhelst blogs about combining ScriptAlias (or a way to run CGIs) and DirectoryIndex in Apache. Recently, developing a TinyURL clone I had a similar (not identical, though) issue. Basically, I set SetHandler to perl-script on the “/” location, which basically means, everything accessed on a given virtual host, is affected. Because you are changing the handler for the entire location, DirectoryIndex will have no effect on it because mod_dir is the one dealing with the DirectoryIndex function, that is, using the DIR_MAGIC_TYPE handler. To fix this you can use a mod_perl (2, I never really used 1) Fixup phase handler:
<VirtualHost *:80>
	...
	# some stuff
	...
	# PerlSections rule.
	<Perl>
	$Location "/"  =  
		SetHandler => 'perl-script',
		# some stuff
		PerlFixupHandler => 'Axiombox::Awbox::Fixup',
		# some other stuff
		DirectoryIndex => 'whatever.html',
	 ;
	</Perl>
</VirtualHost>
If it looks incomplete is because some other information, out of the scope of this sample, like DocumentRoot or other mod_perl directives, are hidden as the “other stuff”. My Fixup.pm handler looks like this:
package Axiombox::Awbox::Fixup;
use strict;
use warnings FATAL => qw(all);
use Apache2::Const -compile => qw(DIR_MAGIC_TYPE OK DECLINED);
use Apache2::RequestRec;
sub handler  
	my $r = shift;
	if ($r->handler eq 'perl-script' &&
		-d $r->filename              &&
		$r->is_initial_req)
	 
		$r->handler(Apache2::Const::DIR_MAGIC_TYPE);
		return Apache2::Const::OK;
	 
	return Apache2::Const::DECLINED;
 
1;
Which is very straight-forward: If the request is set to perl-script, the requested file is a directory and if the current request is the main one, then change the handler and return to the normal flow of phases. Otherwise, decline the Fixup phase handler.

21 November 2008

David Moreno Garza: Book meme

De esta triste estancia en la capital de Colombia se rescata el que pudieron ver jugar al m tico Real Madrid contra el Millonarios.” Translation: “From this sad stay in the capital of Colombia, it was worth they saw the mitical Real Madrid play Millonarios.” From Ernesto Guevara tambi n conocido como el Che (Ernesto Guevara also known as Che), by Paco Ignacio Taibo II.

6 November 2008

David Moreno Garza: Harlem and the elections

A lot has been said about the elections already. I just want to share my personal experiences about it. During the weekend, Tom invited us to his place in lower Harlem (we live upper Harlem) on 123rd St and Adam Clayton Powell Jr Ave, for Tuesday night. As Tuesday arrived, we didn’t see too many people too excited about it. Living in Harlem, we were pretty used to black people supporting Obama, so getting closer and closer to the elections, we didn’t feel people anxious. On Tuesday, we commuted to work and some of our co-workers got to work late because they have been standing in lines for a couple of hours to vote in polls. The whole day was about talking on how much that day was representing for the US and the world, guessing how they results were going to end up, etc. Later at night, Greg, Phil, Raquel and I headed to Tom’s place for his watch-the-results party. His fridge was full of Blue Moon beer, but he also had some Red Stripe :) Since I like to go light on politics, I preferred some other American variantion, Coors Light :) Vermont, Connecticut and a few other New England states were claimed by the Democrats. Matty, a friend of Tom attending the party brought US maps with the electoral votes on each one for people to color them as they were called. It was pretty fun. At some point we forgot about the maps since it was pretty clear that Obama was gonna win. But when they called him at around 11 pm (and I was starting to feel nicely drunk), the whole neighborhood and people in the streets just went completely nuts. It’s something I hadn’t experienced at all in my life, it was like if Mexico would have won the f tbol World Cup (which yes, it will never happen anytime soon :P), but nicer. People went out to the Harlem State Office Building square were cars were honking, and a huge amount of people gathered to celebrate, play brass music, cheer “Yes We Can”. Ghetto guys, white hippies, curious latinos, Africans, African Americans, Puerto Ricans, just a lot, a lot of people, all kinds of them, just a clusterfuck. They projected Obama’s speech from Chicago and people went nuts. It was just, fucking amazing. The images they projected from Harlem to the outside world was in that same square we were in. Our Flickr set for the celebration here.

1 October 2008

David Moreno Garza: New York BSP personal to-do list

So, as it was previously anounced (and recently re-invited by Micah), this weekend is the debiannyc BSP. This makes me think on my lack of involvement on the technical part of Debian (I’m still socially involved with friends and groups) for the last couple of months. So, for the sake of encouraging others to join us on Saturday if you in the city (or the tri-state area, or beyond!), here it is, my personal list of tasks I’m willing to work on: See you at Vireo! UPDATE: The BSP was a lot of fun. Striking now the things I actually did from my list.

24 September 2008

David Moreno Garza: self meme: why not?

From kov: 1. Take a picture of yourself right now.
2. Don t change your clothes, don t fix your hair just take a picture.
3. Post that picture with NO editing.
4. Post these instructions with your picture.

17 September 2008

David Moreno Garza: The Last Day - A short film by Juan P. Guadarrama

Recently, my BFF Wadita (here watching the horizon) moved to Vancouver, BC from Mexico City to continue his studies on 3D animation. In the last months he was producing a short film for his personal portfolio which was finally released: it’s called The Last Day. Even though (as he described it himself) it’s not Pixar-like animation, I really enjoyed it, it’s both melancholic and inspiring. You can go to the film website and watch it on high and low quality with a bunch of neat resources. It’s two minutes long. Go and enjoy it now! Congratulations, Wada ;)

David Moreno Garza: Bug Squashing Party in New York City

stew has announced on the Debian NYC social list the bug squashing party to happen in his place at Brooklyn, NY. If you are around the area and willing to attend, write your name down on the wiki page and get ready to be rewarded by home-brewed beer and grilled bounties per squashed RC bug! stew also offers sleeping facilities in case you need it.

Next.

Previous.